src: add support for write_deployments_with_options
authorFelix Krull <felix.krull@neuland-bfi.de>
Wed, 26 Aug 2020 08:13:01 +0000 (10:13 +0200)
committerColin Walters <walters@verbum.org>
Fri, 6 May 2022 16:53:56 +0000 (12:53 -0400)
rust-bindings/rust/conf/ostree.toml
rust-bindings/rust/src/auto/sysroot.rs
rust-bindings/rust/src/auto/versions.txt
rust-bindings/rust/src/lib.rs
rust-bindings/rust/src/sysroot_write_deployments_opts.rs [new file with mode: 0644]
rust-bindings/rust/sys/src/auto/versions.txt

index 0458b8cfe55a7f5324bb06a5c3bf205ad4edb70f..a3fbdfeab21fdd0aa0cb56515f7a84c9667aff01 100644 (file)
@@ -50,7 +50,6 @@ generate = [
     "OSTree.RepoResolveRevExtFlags",
     "OSTree.SePolicyRestoreconFlags",
     "OSTree.StaticDeltaGenerateOpt",
-    "OSTree.Sysroot",
     "OSTree.SysrootSimpleWriteDeploymentFlags",
     "OSTree.SysrootUpgrader",
     "OSTree.SysrootUpgraderFlags",
@@ -83,6 +82,7 @@ manual = [
     "OSTree.KernelArgs",
     "OSTree.RepoCheckoutAtOptions",
     "OSTree.RepoCheckoutFilter",
+    "OSTree.SysrootWriteDeploymentsOpts",
 ]
 
 ignore = [
@@ -199,6 +199,15 @@ status = "generate"
     pattern = "dummy_.+|ed25519_.+"
     ignore = true
 
+[[object]]
+name = "OSTree.Sysroot"
+status = "generate"
+    [[object.function]]
+    name = "write_deployments_with_options"
+    [[object.function.parameter]]
+    name = "opts"
+    const = true
+
 [[object]]
 name = "OSTree.*"
 status = "generate"
index d5f1583d0e0b33bd085041ff2e710ffc297ec865..9915cc19b7e6610d51735a2bbe50b701144f4b78 100644 (file)
@@ -31,6 +31,8 @@ use Deployment;
 use DeploymentUnlockedState;
 use Repo;
 use SysrootSimpleWriteDeploymentFlags;
+#[cfg(any(feature = "v2017_4", feature = "dox"))]
+use SysrootWriteDeploymentsOpts;
 
 glib_wrapper! {
     pub struct Sysroot(Object<ostree_sys::OstreeSysroot, SysrootClass>);
@@ -356,10 +358,14 @@ impl Sysroot {
         }
     }
 
-    //#[cfg(any(feature = "v2017_4", feature = "dox"))]
-    //pub fn write_deployments_with_options<P: IsA<gio::Cancellable>>(&self, new_deployments: &[Deployment], opts: /*Ignored*/&mut SysrootWriteDeploymentsOpts, cancellable: Option<&P>) -> Result<(), glib::Error> {
-    //    unsafe { TODO: call ostree_sys:ostree_sysroot_write_deployments_with_options() }
-    //}
+    #[cfg(any(feature = "v2017_4", feature = "dox"))]
+    pub fn write_deployments_with_options<P: IsA<gio::Cancellable>>(&self, new_deployments: &[Deployment], opts: &SysrootWriteDeploymentsOpts, cancellable: Option<&P>) -> Result<(), glib::Error> {
+        unsafe {
+            let mut error = ptr::null_mut();
+            let _ = ostree_sys::ostree_sysroot_write_deployments_with_options(self.to_glib_none().0, new_deployments.to_glib_none().0, mut_override(opts.to_glib_none().0), cancellable.map(|p| p.as_ref()).to_glib_none().0, &mut error);
+            if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) }
+        }
+    }
 
     pub fn write_origin_file<P: IsA<gio::Cancellable>>(&self, deployment: &Deployment, new_origin: Option<&glib::KeyFile>, cancellable: Option<&P>) -> Result<(), glib::Error> {
         unsafe {
index 7b36b436c7aa41302a08e773c67d9f113e6cc77e..b14e7670db7977660e67c6b8b16c996f7b15696a 100644 (file)
@@ -1,2 +1,2 @@
 Generated by gir (https://github.com/gtk-rs/gir @ 2d1ffab1)
-from gir-files (https://github.com/gtk-rs/gir-files @ 203ae47)
+from gir-files (https://github.com/gtk-rs/gir-files @ ac0d3c9)
index 64f435cc9444972bcb27d1776ab8436d34a7a3f0..892bca7766c1da0c7f8bad98d79c760a59a1c008 100644 (file)
@@ -53,6 +53,10 @@ pub use crate::se_policy::*;
 mod commit_sizes_entry;
 #[cfg(any(feature = "v2020_1", feature = "dox"))]
 pub use crate::commit_sizes_entry::*;
+#[cfg(any(feature = "v2017_4", feature = "dox"))]
+mod sysroot_write_deployments_opts;
+#[cfg(any(feature = "v2017_4", feature = "dox"))]
+pub use crate::sysroot_write_deployments_opts::*;
 
 // tests
 #[cfg(test)]
diff --git a/rust-bindings/rust/src/sysroot_write_deployments_opts.rs b/rust-bindings/rust/src/sysroot_write_deployments_opts.rs
new file mode 100644 (file)
index 0000000..9c053b2
--- /dev/null
@@ -0,0 +1,55 @@
+use glib::translate::*;
+use ostree_sys::OstreeSysrootWriteDeploymentsOpts;
+
+pub struct SysrootWriteDeploymentsOpts {
+    pub do_postclean: bool,
+}
+
+impl Default for SysrootWriteDeploymentsOpts {
+    fn default() -> Self {
+        SysrootWriteDeploymentsOpts {
+            do_postclean: false,
+        }
+    }
+}
+
+impl<'a> ToGlibPtr<'a, *const OstreeSysrootWriteDeploymentsOpts> for SysrootWriteDeploymentsOpts {
+    type Storage = Box<OstreeSysrootWriteDeploymentsOpts>;
+
+    fn to_glib_none(&'a self) -> Stash<*const OstreeSysrootWriteDeploymentsOpts, Self> {
+        // Creating this struct from zeroed memory is fine since it's `repr(C)` and only contains
+        // primitive types.
+        // The struct needs to be boxed so the pointer we return remains valid even as the Stash is
+        // moved around.
+        let mut options =
+            Box::new(unsafe { std::mem::zeroed::<OstreeSysrootWriteDeploymentsOpts>() });
+        options.do_postclean = self.do_postclean.to_glib();
+        Stash(options.as_ref(), options)
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use glib_sys::{GFALSE, GTRUE};
+
+    #[test]
+    fn should_convert_default_options() {
+        let options = SysrootWriteDeploymentsOpts::default();
+        let stash = options.to_glib_none();
+        let ptr = stash.0;
+        unsafe {
+            assert_eq!((*ptr).do_postclean, GFALSE);
+        }
+    }
+
+    #[test]
+    fn should_convert_non_default_options() {
+        let options = SysrootWriteDeploymentsOpts { do_postclean: true };
+        let stash = options.to_glib_none();
+        let ptr = stash.0;
+        unsafe {
+            assert_eq!((*ptr).do_postclean, GTRUE);
+        }
+    }
+}
index 7b36b436c7aa41302a08e773c67d9f113e6cc77e..b14e7670db7977660e67c6b8b16c996f7b15696a 100644 (file)
@@ -1,2 +1,2 @@
 Generated by gir (https://github.com/gtk-rs/gir @ 2d1ffab1)
-from gir-files (https://github.com/gtk-rs/gir-files @ 203ae47)
+from gir-files (https://github.com/gtk-rs/gir-files @ ac0d3c9)